import axios from './$http'


const cache = new Map();

const api = {
    clearCache() {
        cache.clear();
    },
    async queryAllOutpatientSchedule() {
        const result = await axios.post(`/gw-api/hbos-business-thirdparty-integration/common/osc/deptSearch`, {
            orgId: 20001001,
            attrList: [
                {
                    "attrCode": "outpatientScheduling",
                    "attrValues": ["true"]
                }
            ]
        });
        return result;
    },
    async listDoctorByDeptIds(deptIds) {
        const result = await axios.post(`/gw-api/hbos-business-thirdparty-integration/common/osc/staffSearch`, {
            orgId: 20001001,
            unitIds: deptIds,
            status: 1
        });
        return result;
    },
    async listLocationByType(deptIds) {
        const result = await axios.post(`/gw-api/hbos-business-thirdparty-integration/common/osc/locationSearch`, {
            orgId: 20001001,
            unitIds: deptIds,
            types: ["FH0295.02", "FH0295.03"]
        });
        return result;
    },
    async queryRegisterCategoryList() {
        const result = await axios.post(`/hbos-business-charge-gydfy/service_item/schedule/listServiceItemManagementCategoryByCode`, {
            code: "FH0101.05"
        });
        return result;
    },
    async queryRegisterLevelList(managementCategoryCodeList) {
        const result = await axios.post(`/gw-api/hbos-business-thirdparty-integration/common/osc/serviceItemSearch`, {
            orgId: 20001001,
            managementCategoryCodeList: managementCategoryCodeList,
            status: 1
        });
        return result;

    },

    //找到所有已保存的进行提交
    async listSchedule(deptId, expireDate, validDate) {
        const key = `listSchedule:${deptId}-${expireDate}-${validDate}`;
        const data = cache.get(key);

        if (data) {
            return data;
        }
        const result = await axios.post(`/hbos-business-charge-gydfy/schedule/list`, {
            deptId,
            expireDate,
            validDate
        });

        cache.set(key, result);

        return result;
    },
    async submitSchedule(ids) {
        const result = await axios.post(`/hbos-business-charge-gydfy/schedule/submit`, {
            ids
        });
        return result;
    },
    //relateRuleId
    async submitGenerate(scheduleRuleId) {
        const result = await axios.post(`/hbos-sdc/schedule/generate`, {
            scheduleRuleId
        });
        return result;
    },
    async saveSchedule(data) {
        const result = await axios.post(`/hbos-business-charge-gydfy/schedule/save`, data);
        return result;
    },
    async getShiftList() {
        const key = `getShiftList`;
        const data = cache.get(key);

        if (data) {
            return data;
        }
        const result = await axios.post(`/hbos-atc/shift/list`, {
            "type": "FH0101.05"
        });
        cache.set(key, result);
        return result;
    },
    async getScheduleDeptConfigDetail(deptId) {
        const result = await axios.post(`/hbos-business-charge-gydfy/schedule/dept/detail`, {
            deptId
        });

        return result;
    },
    async saveDeptConfig(data) {
        const result = await axios.post(`/hbos-business-charge-gydfy/schedule/dept/save`, data);
        return result;
    }
}

export default api;